<template>
  <div class="box">
    <h2>子组件 {{$store.state.user.name}}</h2>
    从vuex中获取的值:<label></label>
    <br />
    <button  @click="changeNames('刘超凡')">改名</button>
    <button  @click="changeName('刘超凡')">改名</button>
    
  </div>
</template>

<script>

import {mapMutations} from 'vuex'
export default {
  name: 'AddItem',
 methods:{
  ...mapMutations('setting',['changeName',name]),
  changeNames(name){
    this.$store.commit('user/changeName',name)
  },
 }
  
}
</script>

<style lang="css" scoped>
.box {
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>